//use std::fs::File;
use std::io;
use std::io::Read;
use std::fs::File;

fn f(i: i32) -> Result<i32, bool> {
    if i >= 0 { Ok(i) }
    else { Err(false) }
}

fn read_text_from_file(path: &str) -> Result<String, io::Error> {
    let mut f = File::open(path)?;
    let mut s = String::new();
    f.read_to_string(&mut s)?;
    Ok(s)
}

fn main() {
    /*let f = File::open("my.txt");
        match f {
            Ok(file) => {
                println!("File opened successfully.");
            },
            Err(err) => {
                println!("Failed to open the file.");
            }
       }
    println!("Hello, world!");*/

    //let f1 = File::open("gg.txt").unwrap();
    //let f2 = File::open("cc.txt").expect("Failed to open.");

    /*let r = f(10000);
    if let Ok(v) = r {
        println!("Ok: f(-1) = {}", v);
    } else {
        println!("Err");
    }*/

    let str_file = read_text_from_file("bb.txt");
    match str_file {
        Ok(s) => println!("{}", s),
        Err(e) => {
            match e.kind() {
                io::ErrorKind::NotFound => {
                    println!("No such file");
                },
                _ => {
                    println!("Cannot read the file");
                }
            }
        }
    }

}
